package com.nowcoder.community.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;

/**
 * @author bombax
 * @date 2024-08-18 15:18
 */
//@Component
//@Aspect
public class AlphaAspect {
    @Pointcut("execution(* com.nowcoder.community.service.*.*(..))")
//    @Pointcut("execution(* com.nowcoder.community.controller.HomeController.getIndexPage(..))")
    public void pointcut() {

    }

    @Before("pointcut()")
    public void before(JoinPoint joinPoint) {
        System.out.println("Before Method : " + joinPoint.getSignature().getName());
    }

    @After("pointcut()")
    public void after(JoinPoint joinPoint) {
        System.out.println("After Method : " + joinPoint.getSignature().getName());
    }

    @AfterReturning("pointcut()")
    public void afterReturning(JoinPoint joinPoint) {
        System.out.println("AfterReturning Method : " + joinPoint.getSignature().getName());
    }

    @AfterThrowing("pointcut()")
    public void afterThrowing(JoinPoint joinPoint) {
        System.out.println("AfterThrowing Method : " + joinPoint.getSignature().getName());
    }

    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("Around before Method : " + joinPoint.getSignature().getName());
        Object result = joinPoint.proceed();
        System.out.println("Around after Method : " + joinPoint.getSignature().getName());
        return result;
    }
}
